@inkdropapp/ai 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +65 -6
  2. package/package.json +12 -11
  3. package/src/events.ts +105 -0
  4. package/src/index.ts +15 -4
  5. package/src/provider-constants.ts +11 -37
  6. package/src/provider.ts +13 -1
  7. package/src/providers/anthropic/constants.ts +4 -0
  8. package/src/providers/{anthropic.ts → anthropic/provider.ts} +28 -13
  9. package/src/providers/openai-compatible/constants.ts +32 -0
  10. package/src/providers/{openai-compatible.ts → openai-compatible/provider.ts} +27 -10
  11. package/src/providers/openai-compatible/validator-compiled.d.ts +7 -0
  12. package/src/providers/openai-compatible/validator-compiled.js +4 -0
  13. package/src/providers/openai-compatible/validator.ts +33 -0
  14. package/src/registry.ts +30 -6
  15. package/src/utils/logging-fetch.ts +122 -0
  16. package/src/{internal → utils}/map-ai-sdk-stream.ts +1 -1
  17. package/types/events.d.ts +99 -0
  18. package/types/index.d.ts +4 -4
  19. package/types/provider-constants.d.ts +2 -29
  20. package/types/provider.d.ts +12 -1
  21. package/types/providers/anthropic/constants.d.ts +4 -0
  22. package/types/providers/anthropic/provider.d.ts +42 -0
  23. package/types/providers/openai-compatible/constants.d.ts +25 -0
  24. package/types/providers/openai-compatible/provider.d.ts +47 -0
  25. package/types/providers/openai-compatible/validator-compiled.d.ts +9 -0
  26. package/types/providers/openai-compatible/validator.d.ts +14 -0
  27. package/types/registry.d.ts +12 -1
  28. package/types/utils/logging-fetch.d.ts +13 -0
  29. package/types/utils/map-ai-sdk-error.d.ts +21 -0
  30. package/types/utils/map-ai-sdk-stream.d.ts +25 -0
  31. package/src/stream-events.ts +0 -53
  32. /package/src/{internal → utils}/map-ai-sdk-error.ts +0 -0
@@ -1,53 +0,0 @@
1
- import type { AIError } from './errors.js'
2
-
3
- /**
4
- * Why a completion stream stopped producing output.
5
- *
6
- * Mirrors the AI SDK's `FinishReason`. Unknown / provider-specific values are
7
- * normalised to `'other'` rather than silently passed through.
8
- */
9
- export type FinishReason =
10
- | 'stop'
11
- | 'length'
12
- | 'content-filter'
13
- | 'tool-calls'
14
- | 'error'
15
- | 'other'
16
-
17
- /**
18
- * Token usage for a single completion. Every field is optional because
19
- * not every provider reports every counter.
20
- */
21
- export type Usage = {
22
- /** Tokens consumed from the prompt. */
23
- inputTokens?: number
24
- /** Tokens generated in the response. */
25
- outputTokens?: number
26
- /** `inputTokens + outputTokens` as reported by the provider. */
27
- totalTokens?: number
28
- /** Of `inputTokens`, how many were a cache hit (Anthropic prompt-cache reads). */
29
- cacheReadInputTokens?: number
30
- /** Of `inputTokens`, how many were written to the prompt cache for future reads. */
31
- cacheCreationInputTokens?: number
32
- /** Subset of `outputTokens` spent on reasoning / thinking content. */
33
- reasoningTokens?: number
34
- }
35
-
36
- /**
37
- * Provider-agnostic streaming events. Every concrete provider's stream is
38
- * reduced to this discriminated union so consumers never branch on provider id.
39
- *
40
- * Errors arrive as `{ kind: 'error', ... }` events, not as thrown exceptions —
41
- * this lets the host pump events across an Electron IPC boundary one at a time
42
- * without needing try/catch around the iterator.
43
- *
44
- * `tool-call` and `tool-result` are typed but never produced in the current
45
- * version (one-shot text completions only). They're reserved for forward compat.
46
- */
47
- export type StreamEvent =
48
- | { kind: 'text-delta'; delta: string }
49
- | { kind: 'tool-call'; id: string; name: string; input: unknown }
50
- | { kind: 'tool-result'; id: string; name: string; result: unknown }
51
- | { kind: 'usage-update'; usage: Usage }
52
- | { kind: 'finish'; finishReason: FinishReason; usage: Usage }
53
- | { kind: 'error'; error: AIError }
File without changes