@arcote.tech/arc-ai 0.7.7 → 0.7.8

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-ai",
3
3
  "type": "module",
4
- "version": "0.7.7",
4
+ "version": "0.7.8",
5
5
  "private": false,
6
6
  "description": "AI provider abstraction, completion tracking, and budget management for Arc framework",
7
7
  "main": "./src/index.ts",
@@ -10,8 +10,8 @@
10
10
  "type-check": "tsc --noEmit"
11
11
  },
12
12
  "peerDependencies": {
13
- "@arcote.tech/arc": "^0.7.7",
14
- "@arcote.tech/arc-auth": "^0.7.7",
13
+ "@arcote.tech/arc": "^0.7.8",
14
+ "@arcote.tech/arc-auth": "^0.7.8",
15
15
  "typescript": "^5.0.0"
16
16
  },
17
17
  "devDependencies": {
@@ -96,63 +96,73 @@ export function creditLedger(config: {
96
96
  },
97
97
  )
98
98
 
99
- // ─── topUp — add credits ────────────────────────────────────
99
+ // ─── topUp — add credits (server-internal: listeners, cron, ai-orchestration)
100
100
  .mutateMethod(
101
101
  "topUp",
102
- (fn) => fn.withParams({
103
- scopeId,
104
- amount: number(),
105
- reason: string(),
106
- metadata: string().optional(),
107
- }).handle(
108
- ONLY_SERVER &&
109
- (async (ctx, params) => {
110
- const entryId = ledgerId.generate();
111
- await ctx.credited.emit({
112
- ledgerId: entryId,
113
- scopeId: params.scopeId,
114
- amount: params.amount,
115
- reason: params.reason,
116
- metadata: params.metadata,
117
- });
118
- return { ok: true };
119
- }),
120
- ),
102
+ (fn) => fn
103
+ .private()
104
+ .withParams({
105
+ scopeId,
106
+ amount: number(),
107
+ reason: string(),
108
+ metadata: string().optional(),
109
+ })
110
+ .handle(
111
+ ONLY_SERVER &&
112
+ (async (ctx, params) => {
113
+ const entryId = ledgerId.generate();
114
+ await ctx.credited.emit({
115
+ ledgerId: entryId,
116
+ scopeId: params.scopeId,
117
+ amount: params.amount,
118
+ reason: params.reason,
119
+ metadata: params.metadata,
120
+ });
121
+ return { ok: true };
122
+ }),
123
+ ),
121
124
  )
122
125
 
123
- // ─── deduct — remove credits ────────────────────────────────
126
+ // ─── deduct — remove credits (server-internal: ai consumers)
124
127
  .mutateMethod(
125
128
  "deduct",
126
- (fn) => fn.withParams({
127
- scopeId,
128
- amount: number(),
129
- reason: string(),
130
- model: string().optional(),
131
- metadata: string().optional(),
132
- }).handle(
133
- ONLY_SERVER &&
134
- (async (ctx, params) => {
135
- const entryId = ledgerId.generate();
136
- await ctx.debited.emit({
137
- ledgerId: entryId,
138
- scopeId: params.scopeId,
139
- amount: params.amount,
140
- reason: params.reason,
141
- model: params.model,
142
- metadata: params.metadata,
143
- });
144
- return { ok: true };
145
- }),
146
- ),
129
+ (fn) => fn
130
+ .private()
131
+ .withParams({
132
+ scopeId,
133
+ amount: number(),
134
+ reason: string(),
135
+ model: string().optional(),
136
+ metadata: string().optional(),
137
+ })
138
+ .handle(
139
+ ONLY_SERVER &&
140
+ (async (ctx, params) => {
141
+ const entryId = ledgerId.generate();
142
+ await ctx.debited.emit({
143
+ ledgerId: entryId,
144
+ scopeId: params.scopeId,
145
+ amount: params.amount,
146
+ reason: params.reason,
147
+ model: params.model,
148
+ metadata: params.metadata,
149
+ });
150
+ return { ok: true };
151
+ }),
152
+ ),
147
153
  )
148
154
 
149
- // ─── checkBalance — query current balance ───────────────────
155
+ // ─── checkBalance — query current scope's balance ───────────
150
156
  .clientQuery(
151
157
  "checkBalance",
152
158
  (fn) => fn
153
- .withParams({ scopeId: string() })
154
- .handle(async (ctx, params) => {
155
- const entry = await ctx.$query.findOne({ scopeId: params.scopeId });
159
+ .protectedBy(protectBy, (p: any) => ({
160
+ scopeId: p.workspaceId ?? p.accountId,
161
+ }))
162
+ .handle(async (ctx) => {
163
+ // Scope filter (z protectedBy) jest aplikowany automatycznie do
164
+ // ctx.$query — findOne({}) zwraca tylko wiersz aktualnego scope'u.
165
+ const entry = await ctx.$query.findOne({});
156
166
  const balance = entry?.balance ?? 0;
157
167
  return {
158
168
  balance,
@@ -161,9 +171,7 @@ export function creditLedger(config: {
161
171
  totalDebited: entry?.totalDebited ?? 0,
162
172
  };
163
173
  }),
164
- )
165
-
166
- .protectBy(protectBy, (p: any) => ({ scopeId: p.workspaceId ?? p.accountId }));
174
+ );
167
175
 
168
176
  const elements = [Ledger];
169
177
 
package/src/tool/tool.ts CHANGED
@@ -122,14 +122,14 @@ export class ArcTool<
122
122
  Data["handler"] extends Function
123
123
  ? ServerToolViewProps<
124
124
  Data["params"] extends ArcObjectAny ? $type<Data["params"]> : {},
125
- Data["result"] extends ArcObjectAny
126
- ? $type<Data["result"]>
125
+ Data extends { result: infer R extends ArcObjectAny }
126
+ ? $type<R>
127
127
  : unknown
128
128
  >
129
129
  : InteractiveToolViewProps<
130
130
  Data["params"] extends ArcObjectAny ? $type<Data["params"]> : {},
131
- Data["result"] extends ArcObjectAny
132
- ? $type<Data["result"]>
131
+ Data extends { result: infer R extends ArcObjectAny }
132
+ ? $type<R>
133
133
  : unknown
134
134
  >
135
135
  >,